//把common配置作为基准模板配置文件，通过merge来将各自独特的配置整合。
const common = require('./webpack.common')
const merge = require('webpack-merge')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = merge(common, {
  mode: 'production',
  //覆盖devtool
  devtool: 'none',
  output: {
    filename: "js/[name]-[contenthash:8].bundle.js",
  },
  optimization: {
    //所有的公共模块都提取到bundle当中，实现chunk切割
    splitChunks: {
      chunks: "all"
    },
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin(['public']),
    new HtmlWebpackPlugin({
      title: 'HelloWorld',
      template: './public/index.html',
      favicon: './public/favicon.ico'
    })
  ]
})